using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Week1.particles
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Astroid2D : BaseParticle
    {

        float[] fRadius;
        float[] fY;
        float[] fAngle;
        float[] fScale;

        public Astroid2D(Game game, String textureName, player.Camera camera)
            : base(game, textureName, camera, 1, 1000)
        {
            fRadius = new float[1000];
            fY = new float[1000];
            fAngle = new float[1000];
            fScale = new float[1000];
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            Random oRnd = new Random();
            iCount = 1000;
            float angle = 0;
            float radius = 210;

            for (int iDx = 0; iDx < iCount; iDx++)
            {
                fRotate[iDx] = oRnd.Next(130);
                fAngle[iDx] = angle++;
                fScale[iDx] = (float)((float)oRnd.Next(2, 10)) / 10;

                fRadius[iDx] = oRnd.Next((int)radius - 40, (int)radius);

                fY[iDx] = oRnd.Next(-5, 5);

                oPosition[iDx] = new Vector3(
                    helper.PathHelper.getX(fAngle[iDx], fRadius[iDx]),
                    fY[iDx],
                    helper.PathHelper.getY(fAngle[iDx], fRadius[iDx]));

                oWorld[iDx] = Matrix.CreateWorld(oPosition[iDx], Vector3.Forward, Vector3.Up);
            }

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            for (int iDx = 0; iDx < iCount; iDx++)
            {
                fAngle[iDx] += .01f;

                oPosition[iDx] = new Vector3(
                    helper.PathHelper.getX(fAngle[iDx], fRadius[iDx]),
                    fY[iDx],
                    helper.PathHelper.getY(fAngle[iDx], fRadius[iDx]));

                oWorld[iDx] = Matrix.CreateScale(fScale[iDx])  * Matrix.CreateBillboard(oPosition[iDx], 
                    oCamera.Position, Vector3.Up, Vector3.Forward);
            }

            base.Update(gameTime);
        }

   }
}
